//
//  GQHTransactionInBankController.m
//  Xanthium
//
//  Created by GuanQinghao on 28/02/2018.
//  Copyright © 2018 GuanQinghao. All rights reserved.
//

#pragma mark Macro
#import "GQHHeader.h"

#pragma mark Model

#pragma mark Object

#pragma mark View
#import "GQHTransactionInBankView.h"

#pragma mark Controller
#import "GQHTransactionInBankController.h"
#import "GQHTransactionDetailController.h"

#pragma mark CocoaPods

#pragma mark ----------Header End----------

@interface GQHTransactionInBankController () <GQHTransactionInBankViewDelegate> {
    
#pragma mark Data
    NSMutableArray *inBankArray;
#pragma mark View
    /// 自定义根视图
    GQHTransactionInBankView *rootView;
}

@end


@implementation GQHTransactionInBankController

#pragma mark --Lifecycle
- (void)loadView {
    DLog();
    
    rootView = [[GQHTransactionInBankView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    rootView.qh_delegate = self;
    self.view = rootView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    DLog();
    
    [self fetchServiceData];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    DLog();
    
    self.qh_titleLabel.text = @"选择转入银行账号";
    self.qh_rightButton.hidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    DLog();
}

#pragma mark --Delegate
- (void)qh_selectedRowWithTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *inBankDictinary = inBankArray[indexPath.row];
    NSString *inBankID = [inBankDictinary objectForKey:@"id"];
    GQHTransactionDetailController *detailController = [[GQHTransactionDetailController alloc] init];
    detailController.hidesBottomBarWhenPushed = YES;
    detailController.qh_editable = YES;
    detailController.qh_inBankID = inBankID;
    [self.navigationController pushViewController:detailController animated:YES];
    
}
#pragma mark --TargetMethod

#pragma mark --PrivateMethod
- (void)fetchServiceData {
    
    /// 平台转入银行账号
    NSString *URLString = [[NSString qh_APIURLString] stringByAppendingString:@"/buPlatformBank/1/list"];
    
    [GQHNetHelper qh_requestGET:URLString parameters:nil success:^(NSNumber *code, NSString *message, NSDictionary *data) {
        
        if (0 == [code intValue]) {
            
            inBankArray = [NSMutableArray arrayWithArray:[data objectForKey:@"list"]];
            rootView.qh_contentArray = inBankArray;
            [rootView.qh_tableView reloadData];
        } else {
            
            [self showToastWithText:message];
        }
    } failure:^(NSError *error) {
        
        NSString *errorString = [NSString stringWithFormat:@"网络出错:%@,code:%ld", error.domain, (long)error.code];
        [self qh_alertWithTitle:nil message:errorString actionTitle:nil handler:nil completion:nil];
    }];
}
#pragma mark --Setter

#pragma mark --Getter

#pragma mark --View

@end
